package com.geez.bbl.db.type;


/**
 * User: biniam.gebremichael
 * Date: Sep 7, 2010
 */
public class Verse {
    private int startId, endId;
    private String value;
    private VerseStatus status = VerseStatus.OK;
    boolean paragraph;
    boolean isGeez;

    public Verse(int startId, int endId, String value, VerseStatus status, boolean paragraph, boolean isGeez) {
        this.startId = startId;
        this.endId = endId;
        this.value = value;
        this.status = status;
        this.paragraph = paragraph;
        this.isGeez = isGeez;

    }

    public int getStartId() {
        return startId;
    }

    public int getEndId() {
        return endId;
    }

    public boolean isParagraph() {
        return paragraph;
    }

    public String getPlainValue() {
    return value;
    }

    public String getValue() {
        if(isGeez){
        return toGeez(value);
        }else{
            return value.replaceAll("'","''").trim();
        }
    }

    public VerseStatus getStatus() {
        return status;
    }

     public static String toGeez(String vs) {
        String[] contents = vs.split("\\s+");
        StringBuilder line = new StringBuilder();

        for (String ss : contents) {
            String[] one = ss.split("");
            for (String s : one) {
                if (s.length()>0 && (s.charAt(0) > 4000 || s.equals(":"))) {
                    line.append(s);
                }
            }
            line.append(" ");
        }

        return line.toString().trim();


    }

    @Override
    public String toString() {
        return "["  + startId +
                "-" + endId +
                "] " + getValue() + '\'' ;
    }
}
